import {get, post} from "./Request.ts";
import {ADD_ORDER_URL, CATEGORY_URL, DETAIL_URL, FOOTER_URL, Head, HOME_URL, SEARCH_URL} from "./Api.ts";

/**
 * 获取首页数据
 */
export const fetchHomeData = <T = any>(params?: Record<string, any>) => {
    return get<T>(HOME_URL, params);
}

/**
 *  获取分类列表
 */
export const fetchCategoryList = <T = any>(params?: Record<string, any>) => {
    return get<T>(CATEGORY_URL, params);
}

/**
 * 获取商品详情
 */
export const fetchProductDetail = <T = any>(params?: Record<string, any>) => {
    return get<T>(DETAIL_URL, params);
}

/**
 * 搜索
 */
export const fetchSearch = <T = any>(params?: Record<string, any>) => {
    return get<T>(SEARCH_URL, params);
}

/**
 * 获取页脚信息
 */
export const fetchFooter = <T = any>(params?: Record<string, any>) => {
    return get<T>(FOOTER_URL, params);
}

/**
 * 提交订单
 */
export const fetchSubmitOrder = <T = any>(data: FormData) => {
 return post<T>(ADD_ORDER_URL, data, {
     headers: {
         'Content-Type': 'multipart/form-data'
     }
 })
}

/**
 * 获取头部数据
 */
export const fetchHeader = <T = any>(params?: Record<string, any>) => {
    return get<T>(Head, params);
}
